package br.com.fafica.fast_restaurant.view;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import br.com.fafica.fast_restaurant.control.ControlMesa;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class TelaCadastroMesa extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldQuantLugares;
	private JTextField textFieldCodigo;

			public void run() {
				try {
					TelaCadastroMesa frame = new TelaCadastroMesa();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

	public TelaCadastroMesa() {
		setTitle("CADASTRO MESA");
		final TelaCadastroMesa estaTela = this;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 491, 320);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(0, 100, 0));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel label = new JLabel("CADASTRO MESA");
		label.setVerticalAlignment(SwingConstants.BOTTOM);
		label.setForeground(new Color(255, 215, 0));
		label.setFont(new Font("Arial Black", Font.PLAIN, 20));
		
		JButton button = new JButton("SAIR");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				estaTela.setVisible(false);
				TelaCadastro telaCadastro = new TelaCadastro();
				telaCadastro.setVisible(true);
				
			}
		});
		button.setOpaque(false);
		
		textFieldQuantLugares = new JTextField();
		textFieldQuantLugares.setColumns(10);
		
		JLabel label_1 = new JLabel();
		label_1.setText("QUANTIDADE DE LUGARES:");
		label_1.setForeground(new Color(255, 215, 0));
		label_1.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_1.setBackground(Color.GRAY);
		
		JButton button_1 = new JButton("SALVAR");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int cod = Integer.parseInt(textFieldCodigo.getText()); 
				int quant_1 = Integer.parseInt(textFieldQuantLugares.getText());
				
				ArrayList<Integer> Registro = new ArrayList<Integer>();
				Registro.add(cod);
				Registro.add(quant_1);
			

				ControlMesa ControllerMesa = new ControlMesa();
				ControllerMesa.Salvar(Registro);

				estaTela.setVisible(false);
				TelaCadastro telaCadastro = new TelaCadastro();
				telaCadastro.setVisible(true);

			}
		});
		
		textFieldCodigo = new JTextField();
		textFieldCodigo.setColumns(10);
		
		JLabel label_2 = new JLabel();
		label_2.setText("C\u00D3DIGO:");
		label_2.setForeground(new Color(255, 215, 0));
		label_2.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_2.setBackground(Color.GRAY);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(48, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(textFieldQuantLugares, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)
							.addGap(10)
							.addComponent(textFieldCodigo, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
						.addComponent(label, GroupLayout.PREFERRED_SIZE, 203, GroupLayout.PREFERRED_SIZE))
					.addGap(139))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addGap(147)
					.addComponent(button_1)
					.addGap(18)
					.addComponent(button, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(202, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(19)
					.addComponent(label, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
					.addGap(51)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(1)
							.addComponent(textFieldCodigo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textFieldQuantLugares, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
					.addGap(25))
		);
		contentPane.setLayout(gl_contentPane);
	}

}
